var root = require('../app.js');
var app = require('express')();
var concat = require('concat-stream');
var request = require('request');
var log = console.log.bind(console);
var lerror = console.error.bind(console);

root.use('/ice',app);

app.get('/a',(req,res,next)=>{
//    console.log(req);
//    res.json(req);
    request.get({
        url: 'https://instant.io/rtcConfig',
        // method: req.method,
        // rejectUnauthorized: false
    })
    .pipe(concat((config)=>{
try{
        res.json(JSON.parse(config));
}catch(e){
	console.log(e);
	res.json({
    iceServers:[
      {
        url:"stun:23.21.150.121",
        urls:"stun:23.21.150.121"
      },
      {
        url:"turn:global.turn.twilio.com:3478?transport=udp",
        username:"bec4bff494fe57390e1c469a76998c605d4a4ee3fab2eb14becba1fc580b4343",
        credential:"06Eu70ZD072h/GXjFFofqKQtXV4WrLR+nkhVqnSpJ8I=",
        urls:"turn:global.turn.twilio.com:3478?transport=udp"
      },
      {
        url:"turn:global.turn.twilio.com:3478?transport=tcp",
        username:"bec4bff494fe57390e1c469a76998c605d4a4ee3fab2eb14becba1fc580b4343",
        credential:"06Eu70ZD072h/GXjFFofqKQtXV4WrLR+nkhVqnSpJ8I=",
        urls:"turn:global.turn.twilio.com:3478?transport=tcp"
      },
      {
        url:"turn:global.turn.twilio.com:443?transport=tcp",
        username:"bec4bff494fe57390e1c469a76998c605d4a4ee3fab2eb14becba1fc580b4343",
        credential:"06Eu70ZD072h/GXjFFofqKQtXV4WrLR+nkhVqnSpJ8I=",
        urls:"turn:global.turn.twilio.com:443?transport=tcp"
      },
      {url:'stun:stun01.sipphone.com'},
      {url:'stun:stun.ekiga.net'},
      {url:'stun:stun.fwdnet.net'},
      {url:'stun:stun.ideasip.com'},
      {url:'stun:stun.iptel.org'},
      {url:'stun:stun.rixtelecom.se'},
      {url:'stun:stun.schlund.de'},
      {url:'stun:stun.l.google.com:19302'},
      {url:'stun:stun1.l.google.com:19302'},
      {url:'stun:stun2.l.google.com:19302'},
      {url:'stun:stun3.l.google.com:19302'},
      {url:'stun:stun4.l.google.com:19302'},
      {url:'stun:stunserver.org'},
      {url:'stun:stun.softjoys.com'},
      {url:'stun:stun.voiparound.com'},
      {url:'stun:stun.voipbuster.com'},
      {url:'stun:stun.voipstunt.com'},
      {url:'stun:stun.voxgratia.org'},
      {url:'stun:stun.xten.com'},
      {
        url: 'turn:numb.viagenie.ca',
        credential: 'muazkh',
        username: 'webrtc@live.com'
      },
      {
        url: 'turn:192.158.29.39:3478?transport=udp',
        credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
        username: '28224511:1379330808'
      },
      {
        url: 'turn:192.158.29.39:3478?transport=tcp',
        credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=',
        username: '28224511:1379330808'
      }
      ]
    });
}
    }));
});

app.get('/b',(req,res,next)=>{
	res.json({
    iceServers:[
      {
        url:"stun:115.29.34.237",
        urls:"stun:115.29.34.237"
      }
      ]
    });
});